/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pool.socket;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.Topic;
import org.apache.activemq.ActiveMQConnectionFactory;

public class MQConsumer extends Thread {
	private String brokerURL = "tcp://192.168.16.171:61616/";

	// private static String brokerURL = "tcp://127.0.0.1:61616/";

	public void start() {
		ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
				brokerURL);
		Connection connection = null;
		try {
			connection = connectionFactory.createConnection();
			connection.setClientID("testid-123");
			connection.start();
			Session session = connection.createSession(false,
					Session.AUTO_ACKNOWLEDGE);
			Topic topic = session.createTopic("IOT.PerfData.Agriculture");
			MessageConsumer consumer = session.createDurableSubscriber(topic,
					"testid-123");
			consumer.setMessageListener(new MQListener());
		} catch (JMSException e) {
			e.printStackTrace();
			try {
				connection.close();
			} catch (JMSException ex) {
				ex.printStackTrace();
			}
		}

	}

}
